package com.qf.service.impl;

import com.qf.entity.Profile;
import com.qf.mapper.ProfileMapper;
import com.qf.service.ProfileService;
import com.qf.util.AliyunOSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Collections;
import java.util.List;

/**
 * --- 冲 ---
 *
 * @author Biggen
 * @date 2025/5/6
 * @desc
 */
@Service
public class ProfileServiceImpl implements ProfileService {

    @Autowired
    private ProfileMapper mapper;

    @Override
    public String AvatarUpload(MultipartFile file) {
        // 上传图片到OSS,获取图片相对路径
        String relativePath = AliyunOSSUtil.upLoad(file);
        // 更新到数据库
        boolean isUpdated = mapper.updateAvatarUrl(relativePath);
        if (!isUpdated){
            throw new RuntimeException("更新图片路径失败");
        }
        return relativePath;
    }

    @Override
    public boolean updateProfile(Profile profile) {
        return mapper.updateProfile(profile);
    }

    @Override
    public List<Profile> getAllProfile() {
        return mapper.getAllProfile();
    }
}
